<?php
namespace app\adm\model;
use think\Db;

class Order
{
    public function Lists($ordernumber='')
    {
        $listPage=Db::name('order')->order('addtime desc')->where($ordernumber)->paginate(10);
        $list=$listPage->all();
        foreach ($list as $key => $value) {
            $ordergoods=Db::name('OrderGoods')->where('orderId = '.$value['orderId'])->select();
            $user=Db::name('user')->where('userid = '.$value['userid'])->find();
            $list[$key]['nickname']=$user['nickname'];
            $list[$key]['tel']=$user['tel'];
            foreach ($ordergoods as $k => $v) {
                $goods=Db::name('goods')->where('goodsId = '.$v['goodsId'])->find();
                $ordergoods[$k]['goodsId']=$goods['goodsId'];
                $ordergoods[$k]['goodsName']=$goods['goodsName'];
                $ordergoods[$k]['goodsMoney']=$goods['goodsMoney'];
                $ordergoods[$k]['specification']=$goods['specification'];
                $ordergoods[$k]['photo']=DB::name('GoodsPhoto')->where('goodsId = '.$goods['goodsId'])->value('photo');
            }
            $list[$key]['goods']=$ordergoods;
            switch ($value['ordertype']) {
                case '1':
                    $list[$key]['state']='未付款';    
                    break;
                case '2':
                    $list[$key]['state']='待发货';
                    break;
                case '3':
                    $list[$key]['state']='待收货';
                    break;
                case '4':
                    $list[$key]['state']='待评价';
                    break;
                case '5':
                    $list[$key]['state']='已评价';
                    break;
                case '6':
                    $list[$key]['state']='已取消';
                    break;
                    
            }
        }
        $list_s['listPage']=$listPage;
        $list_s['list']=$list;
        if($list){
            return $list_s;
        }else{
            return false;
        }
    }
    /**
    * 订单详情
    */
    public function detail($orderId)
    {
        $where['orderId']=$orderId;
        $ordergoods=Db::name('OrderGoods')->where($where)->select();
        foreach ($ordergoods as $key => $value) {
            $goods=Db::name('goods')->where('goodsId = '.$value['goodsId'])->find();
            $photo=Db::name('GoodsPhoto')->where('goodsId = '.$goods['goodsId'])->value('photo');
            $ordergoods[$key]['numbers']=$value['numbers'];
            $ordergoods[$key]['goodsName']=$goods['goodsName'];
            $ordergoods[$key]['goodsMoney']=$goods['goodsMoney'];
            $ordergoods[$key]['photo']=$photo;
        }
        if($ordergoods){
            return $ordergoods;
        }else{
            return false;
        }
    }

}